/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  							 combat_terrain_map.h

	$Header: /heroes4/combat_terrain_map.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( COMBAT_TERRAIN_MAP_H_INCLUDED )
#define COMBAT_TERRAIN_MAP_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "isometric_map.h"
#include "sized_int_types.h"

class  t_battlefield;
class  t_combat_creature;
struct t_map_rect_2d;

// ------------------------------------------------------------------
// enum describing what the bits in the terrain cost maps mean
// ------------------------------------------------------------------

enum t_combat_terrain_flag
{
	k_combat_terrain_has_water,
	k_combat_terrain_has_grass,
	k_combat_terrain_has_rough,
	k_combat_terrain_has_swamp,
	k_combat_terrain_has_lava,
	k_combat_terrain_has_snow,
	k_combat_terrain_has_sand,
	k_combat_terrain_has_dirt,
	k_combat_terrain_has_subterranean,

	k_combat_terrain_has_river,
	k_combat_terrain_has_quicksand,

	k_combat_terrain_has_grass_brush,
	k_combat_terrain_has_rough_brush,
	k_combat_terrain_has_swamp_brush,
	k_combat_terrain_has_lava_brush,
	k_combat_terrain_has_snow_brush,
	k_combat_terrain_has_sand_brush,
	k_combat_terrain_has_dirt_brush,
	k_combat_terrain_has_subterranean_brush,

	k_combat_terrain_flag_count,

	k_combat_terrain_bit_water				= 1 << k_combat_terrain_has_water,
	k_combat_terrain_bit_grass				= 1 << k_combat_terrain_has_grass,
	k_combat_terrain_bit_rough				= 1 << k_combat_terrain_has_rough,
	k_combat_terrain_bit_swamp				= 1 << k_combat_terrain_has_swamp,
	k_combat_terrain_bit_lava				= 1 << k_combat_terrain_has_lava,
	k_combat_terrain_bit_snow				= 1 << k_combat_terrain_has_snow,
	k_combat_terrain_bit_sand				= 1 << k_combat_terrain_has_sand,
	k_combat_terrain_bit_dirt				= 1 << k_combat_terrain_has_dirt,
	k_combat_terrain_bit_subterranean		= 1 << k_combat_terrain_has_subterranean,

	k_combat_terrain_bit_river				= 1 << k_combat_terrain_has_river,
	k_combat_terrain_bit_quicksand			= 1 << k_combat_terrain_has_quicksand,

	k_combat_terrain_bit_grass_brush		= 1 << k_combat_terrain_has_grass_brush,
	k_combat_terrain_bit_rough_brush		= 1 << k_combat_terrain_has_rough_brush,
	k_combat_terrain_bit_swamp_brush		= 1 << k_combat_terrain_has_swamp_brush,
	k_combat_terrain_bit_lava_brush			= 1 << k_combat_terrain_has_lava_brush,
	k_combat_terrain_bit_snow_brush			= 1 << k_combat_terrain_has_snow_brush,
	k_combat_terrain_bit_sand_brush			= 1 << k_combat_terrain_has_sand_brush,
	k_combat_terrain_bit_dirt_brush			= 1 << k_combat_terrain_has_dirt_brush,
	k_combat_terrain_bit_subterranean_brush	= 1 << k_combat_terrain_has_subterranean_brush,
};

// ------------------------------------------------------------------
// isometric map of bitsets showing for a given footprint, which terrains
// will be overlapped.
// ------------------------------------------------------------------
class t_combat_terrain_map : public t_isometric_map<t_uint32>
{
public:
	t_combat_terrain_map( int footprint_size, t_battlefield& battlefield );

	void refresh( t_combat_creature const*	army );
	void refresh( t_map_rect_2d const& rect, t_combat_creature const* army );
	int  get_footprint_size() const;
protected:
	void set_points( t_map_rect_2d const& rect, t_combat_creature const* army );

	int m_footprint_size;
	t_battlefield& m_battlefield;
};

inline int t_combat_terrain_map::get_footprint_size() const
{
	return m_footprint_size;
}

// ------------------------------------------------------------------
// structure pairing a combat terrain bit and a cost
// ------------------------------------------------------------------
struct t_terrain_bit_cost
{
	t_terrain_bit_cost( t_uint32 bit_arg, int cost_arg );

	t_uint32 bit;
	int		 cost;
};

inline t_terrain_bit_cost::t_terrain_bit_cost( t_uint32 bit_arg, int cost_arg )
{
	bit = bit_arg;
	cost = cost_arg;
}


inline bool operator<( t_terrain_bit_cost const& left, t_terrain_bit_cost const& right )
{
	return left.cost < right.cost;
}

// ------------------------------------------------------------------
// array, sorted from least to most, of costs associated with bits
// ------------------------------------------------------------------
class t_terrain_bit_cost_array : public std::vector<t_terrain_bit_cost>
{
public:
	void compute( t_combat_creature const& army );
};

#endif